<template>
  <div class="app-container om-reject-box">
    <div class="layout-box1">
      <div class="search-box">
        <!-- 搜索数据 -->
        <div class="search-input">
          <el-input
            class="input-data"
            v-if="detailStatus == true"
            placeholder="销售订单号"
            v-model="searchForm.pp"
            clearable
          >
          </el-input>
          <el-input
            class="input-data"
            placeholder="单据编码"
            v-model="searchForm.omCode"
            clearable
          ></el-input>
          <el-input
            class="input-data"
            placeholder="客户名称"
            v-model="searchForm.customer"
            clearable
          ></el-input>
          <el-input
            class="picker-data"
            placeholder="销售员"
            v-model="searchForm.workStaff"
            clearable
          ></el-input>
          <el-input
            class="input-data"
            placeholder="物料名称"
            v-if="detailStatus == true"
            v-model="searchForm.searchValue"
            clearable
          ></el-input>
          <el-select
            class="picker-data"
            style="margin-right: 15px"
            placeholder="单据状态"
            v-if="detailStatus == false"
            clearable
            v-model="searchForm.invoiceStatus"
            @click.native="getStatus()"
          >
            <el-option
              v-for="dict in optionsinvoiceStatus"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
          <el-select
            class="picker-data"
            style="margin-right: 15px"
            placeholder="业务状态"
            v-if="detailStatus == false"
            clearable
            v-model="searchForm.workStatus"
            @click.native="getWorkStatus()"
          >
            <el-option
              v-for="dict in optionsworkStatus"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
          <el-date-picker
            v-model="valueDate"
            type="daterange"
            align="right"
            unlink-panels
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
          >
          </el-date-picker>
        </div>
        <div class="search-btn">
          <el-button
            v-if="detailStatus == false"
            type="primary"
            v-hasPermi="['om:reject:query']"
            icon="el-icon-search"
            @click="searchList('bill')"
            >搜索
          </el-button>
          <el-button
            v-else
            type="primary"
            v-hasPermi="['om:reject:query']"
            icon="el-icon-search"
            @click="searchList('detail')"
            >搜索
          </el-button>
        </div>
      </div>
      <el-row :gutter="10" class="mb8" v-if="detailStatus == false">
        <div class="con-top">
          <div class="top-left">
            <el-col :span="1.5">
              <el-button
                type="primary"
                v-hasPermi="['om:reject:detail']"
                icon="el-icon-menu"
                size="mini"
                @click="detailView"
              >
                明细</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="primary"
                v-hasPermi="['om:reject:query']"
                plain
                icon="el-icon-menu"
                size="mini"
                @click="handleCheckleAll"
                >查询所有</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="primary"
                v-hasPermi="['om:reject:entity:add']"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="jumpAdd"
                >新增</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                v-hasPermi="['om:reject:remove']"
                plain
                icon="el-icon-delete"
                size="mini"
                @click="batchDelete"
                :disabled="batchStatus"
              >
                删除</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                v-hasPermi="['om:reject:permit']"
                plain
                icon="el-icon-bell"
                size="mini"
                @click="batchExamine"
                :disabled="batchStatus"
                >审核
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="info"
                v-hasPermi="['om:reject:revoke']"
                plain
                icon="el-icon-close-notification"
                size="mini"
                @click="batchDeExamine"
                :disabled="batchStatus"
                >反审核</el-button
              >
            </el-col>
          </div>
        </div>
      </el-row>
      <el-row
        :gutter="10"
        class="mb8"
        v-if="detailStatus == true"
        style="display: flex; align-items: center"
      >
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-menu"
            size="mini"
            @click="billView"
            >单据
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-menu"
            size="mini"
            @click="handleCheckleDetail"
            >查询所有</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="primary"
            v-hasPermi="['om:reject:entity:add']"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="jumpAdd"
            >新增</el-button
          >
        </el-col>
        <el-col :span="1.5" v-if="$route.query.workType !== ''">
          <el-button
            type="primary"
            v-hasPermi="['om:reject:entity:add']"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="jumpAdd"
            >新增</el-button
          >
        </el-col>

        <el-col :span="1.5">
          <el-button
            style="margin-left: 5px"
            type="warning"
            plain
            icon="el-icon-download"
            v-if="detailStatus == true"
            size="mini"
            @click="handleExport"
            v-hasPermi="['om:reject:export']"
            >导出</el-button
          >
        </el-col>
      </el-row>
      <!-- 单据列表 -->
      <el-table
        :key="tableKey"
        ref="tableHeight"
        :data="tableData"
        border
        style="width: 100%"
        v-if="detailStatus == false"
        :row-class-name="tableRowClassName"
        v-loading="loading"
        :height="maxHeight"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="50" align="center">
        </el-table-column>
        <el-table-column prop="omCode" label="单据编码" align="center">
          <template v-slot="scope">
            <span class="red-scarlet">{{ scope.row.omCode }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="invoiceDate"
          label="单据日期"
          align="center"
          sortable
        >
          <template v-slot="scope">
            <span>{{ scope.row.invoiceDate | inMaterTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="invoiceStatus"
          label="单据状态"
          align="center"
          width="120"
        >
          <template v-slot="scope">
            <div class="order-status">
              <span
                v-if="scope.row.invoiceStatus == '0'"
                style="color: #e6a23c"
                >{{ scope.row.params.sys_invoice_status }}</span
              >
              <span
                v-if="scope.row.invoiceStatus == '1'"
                style="color: #67c23a"
                >{{ scope.row.params.sys_invoice_status }}</span
              >
              <span
                v-if="scope.row.invoiceStatus == '2'"
                style="color: #909399"
                >{{ scope.row.params.sys_invoice_status }}</span
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="params.om_Reject_type"
          label="业务类型"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="customer"
          label="销售客户"
          align="center"
          width="400"
        >
        </el-table-column>
        <el-table-column
          prop="workStaff"
          label="销售员"
          align="center"
          width="100"
        >
        </el-table-column>
        <el-table-column
          prop="params.sys_work_status"
          label="业务状态"
          align="center"
          width="120"
        >
        </el-table-column>
        <el-table-column prop="checkDate" label="审核日期" align="center">
          <template v-slot="scope">
            <span v-if="scope.row.checkDate !== null">{{
              scope.row.checkDate | inMaterTime
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150" align="center">
          <template v-slot="scope">
            <div class="public-btn">
              <el-link
                type="primary"
                v-hasPermi="['om:reject:entity:view']"
                @click="jumpDetail(scope.row.omCode)"
                >查看
              </el-link>
              <el-link
                type="success"
                v-hasPermi="['om:reject:entity:edit']"
                @click="jumpUpdate(scope.row.omCode)"
                :disabled="scope.row.invoiceStatus == '1'"
                >编辑</el-link
              >
              <el-link
                type="danger"
                v-hasPermi="['om:reject:remove']"
                :disabled="scope.row.invoiceStatus == '1'"
                @click="handleDelete(scope.row)"
              >
                删除</el-link
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 明细列表 -->
      <el-table
        v-if="detailStatus == true"
        ref="tableDetailHeight"
        :data="detailTableData"
        border
        style="width: 100%"
        v-loading="detailLoading"
        :height="detailMaxHeight"
        :key="tableKey2"
        :row-class-name="tableRowClassName"
      >
        <el-table-column type="index" width="50" align="center" label="序号">
        </el-table-column>
        <el-table-column
          prop="pp_number"
          label="销售订单号"
          align="center"
          width="120"
        >
          <template v-slot="scope">
            <div>
              <span>{{ scope.row.pp_number }}</span>
            </div>
          </template>
        </el-table-column>

        <el-table-column
          prop="om_code"
          label="单据编码"
          align="center"
          width="120"
        >
          <template v-slot="scope">
            <div>
              <span
                style="color: #1890ff"
                @click="jumpDetail(scope.row.om_code)"
                >{{ scope.row.om_code }}</span
              >
            </div>
          </template>
        </el-table-column>
             <el-table-column label="单据状态" align="center" width="120">
          <template v-slot="scope">
            <div class="order-status">
              <span v-if="scope.row.invoice_status == '0'" style="color: #e6a23c"
                >开立</span
              >
              <span v-if="scope.row.invoice_status == '1'" style="color: #67c23a"
                >审核</span
              >
              <span v-if="scope.row.invoice_status == '2'" style="color: #909399"
                >退回</span
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="customer"
          label="客户名称"
          align="center"
          width="250"
        >
          <template v-slot="scope">
            <div @click="handleClose">
              <span>{{ scope.row.customer }}</span>
            </div>
          </template>
        </el-table-column>

        <el-table-column
          prop="inv_name"
          label="物料名称"
          align="center"
          width="300"
        >
          <template v-slot="scope">
            <div>
              <span
                @click="handleDawer(scope.row)"
                v-if="scope.row.wi_quantity > 0"
                :style="
                  scope.row.quantity == scope.row.wi_quantity
                    ? 'color: #13ce66'
                    : 'color:#1890ff'
                "
                >{{ scope.row.inv_name }} {{ scope.row.inv_attribute }}</span
              >
              <span
                @click="handleDawer(scope.row)"
                v-else
                style="color: #606266"
                >{{ scope.row.inv_name }} {{ scope.row.inv_attribute }}</span
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="inv_code"
          label="物料编码"
          align="center"
          width="140"
        >
        </el-table-column>
        <el-table-column
          prop="batchNumber"
          label="批号"
          align="center"
          width="140"
        >
        </el-table-column>
        <el-table-column prop="quantity" label="退货数量" align="center">
          <template v-slot="scope">
            <div style="text-align: right">
              <span>{{ scope.row.quantity }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="wi_quantity" label="入库数量" align="center">
          <template v-slot="scope">
            <div style="text-align: right">
              <span>{{ scope.row.wi_quantity }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          v-if="parametersSetting.invFeature == 'AC'"
          prop="pkg_type"
          label="包装规格"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="invoice_date"
          label="单据日期"
          align="center"
          width="100"
        >
          <template v-slot="scope">
            <span v-if="scope.row.invoice_date !== null">{{
              scope.row.invoice_date | inMaterTime
            }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 详情抽屉 -->
    <el-drawer
      :title="drawerTitle"
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose"
      size="928px"
      class="drawer-detail"
    >
      <div class="drawer-list-box" v-if="drawerData !== null">
        <div class="drawer-table">
          <h2>客户信息</h2>
          <div class="table-border">
            <table
              class="table-left"
              cellspacing="0"
              style="background-color: #f7f7f8"
            >
              <tr>
                <td>客户名称</td>
                <td>{{ drawerData.customer }}</td>
              </tr>

              <tr>
                <td>销售员</td>
                <td>{{ drawerData.work_staff }}</td>
              </tr>
              <tr>
                <td>业务类型</td>
                <td>{{ drawerData.work_type }}</td>
              </tr>
              <tr>
                <td>退货日期</td>

                <td>{{ drawerData.invoice_date | inMaterTime }}</td>
              </tr>
            </table>
          </div>
        </div>
        <div class="drawer-table inv-table">
          <el-tabs v-model="activeName" class="order-tab">
            <el-tab-pane label="物料信息" name="first" class="table-right">
              <div class="drawer-content">
                <div class="content-t">
                  <p>
                    <label>单据编码：</label>
                    <span>{{ drawerData.om_code }}</span>
                  </p>
                </div>
                <div class="drawer-box">
                  <div class="awer-l">
                    <div class="content-t" style="height: 41px">
                      <p>
                        <label>物料编码：</label>
                        <span>{{ drawerData.inv_code }}</span>
                      </p>
                    </div>
                    <div class="content-t">
                      <p>
                        <label>包装规格：</label>
                        <span>{{ drawerData.pkg_type }}</span>
                      </p>
                    </div>
                    <div class="content-t">
                      <p>
                        <label>退货数量：</label>
                        <span>{{ drawerData.quantity }}</span>
                      </p>
                    </div>
                  </div>
                  <div class="awer-r">
                    <div class="content-t con-height">
                      <p>
                        <label>物料名称：</label>
                        <span
                          v-if="drawerData.wi_quantity > 0"
                          :style="
                            drawerData.quantity == drawerData.wi_quantity
                              ? 'color: #13ce66'
                              : 'color:#1890ff'
                          "
                          >{{ drawerData.inv_name }}</span
                        >
                        <span v-else style="color: #333">{{
                          drawerData.inv_name
                        }}</span>
                      </p>
                    </div>
                    <div class="content-t">
                      <p>
                        <label>包装件数：</label>
                        <span>{{ drawerData.piece }}</span>
                      </p>
                    </div>

                    <div class="content-t">
                      <p>
                        <label>入库数量：</label>
                        <span>{{ drawerData.wi_quantity }}</span>
                      </p>
                    </div>
                  </div>
                </div>
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>
      <div class="drawer-detail-table">
        <el-table
          ref="tableDetailHeight"
          :data="drawerTableData"
          border
          style="width: 100%"
          v-loading="drawerTableLoading"
          :height="drawerTableMaxHeight"
          :row-class-name="tableRowClassName"
        >
          <el-table-column type="index" width="50" align="center" label="序号">
          </el-table-column>
          <el-table-column
            prop="code"
            label="单据编码"
            align="center"
            width="110"
          >
            <template v-slot="scope">
              <div>
                <span
                  style="color: #1890ff"
                  @click="handleViewBill(scope.row)"
                  >{{ scope.row.code }}</span
                >
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="invoice_name"
            label="单据类型"
            align="center"
            width="95"
          >
          </el-table-column>
          <el-table-column
            prop="type_name"
            label="业务类型"
            align="center"
            width="80"
          >
          </el-table-column>
          <el-table-column
            prop="date"
            label="单据日期"
            align="center"
            width="100"
          >
          </el-table-column>
          <el-table-column
            prop="inv_code"
            label="物料编码"
            align="center"
            width="100"
          >
          </el-table-column>
          <el-table-column prop="inv_name" label="物料名称" align="center">
            <template v-slot="scope">
              <div>
                <span
                  >{{ scope.row.inv_name }} {{ scope.row.inv_attribute }}</span
                >
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="unit_name"
            label="主计量"
            align="center"
            width="80"
          >
          </el-table-column>
          <el-table-column prop="quantity" label="数量" align="center">
            <template v-slot="scope">
              <div style="text-align: right">
                <span>{{ scope.row.quantity }}</span>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-drawer>
    <!-- 单据分页 -->
    <pagination
      v-if="total > 0 && detailStatus == false"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getBillList"
    />
    <!-- 明细分页 -->
    <pagination
      v-if="detailTotal > 0 && detailStatus == true"
      :total="detailTotal"
      :page.sync="queryDetail.pageNum"
      :limit.sync="queryDetail.pageSize"
      @pagination="getDetailList"
    />
  </div>
</template>

<script>
import {
  dictMatching, //字典
  listBill, //单据列表
  deleteBill, // 删除单条
  batchDeleteInMaster, //批量删除
  examineBill, //批量审核
  examineDeBill, //批量反审核
  listRejectDetail, //查询明细
  billParameters, //单据参数
  exportDetail, //明细导出
  listLink, //单据关联查询
} from "../../api/reject";
import print from "print-js"; //打印js
export default {
  name: "Reject",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 单据查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        omCode: "", //单据编码
        invoiceStatus: "", //单据状态
        workType: this.$route.query.workType,
      },
      // 开始时间/结束时间配置
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date(
                new Date(new Date().toLocaleDateString()).getTime()
              );
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date(
                new Date(new Date().toLocaleDateString()).getTime()
              );
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date(
                new Date(new Date().toLocaleDateString()).getTime()
              );
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      valueDate: "",
      //明细状态
      detailStatus: true,
      activeName: "first",
      //单据表格key
      tableKey: "",
      // 搜索表单
      searchForm: {
        omCode: "", //单据编码
        startDate: "",
        endDate: "",
        invoiceStatus: "",
        workStaff: "",
        customer: "",
        contractNo: "",
        searchValue: "", //物料名称
        workStatus: "", //业务状态
        pp: "",
      },
      //单据参数信息
      parametersSetting: {
        decimalQuantity: "2", //数量小数位数
        decimalPrice: "2",
        invFeature: "'null'",
      },
      //单据状态
      optionsinvoiceStatus: [],
      //业务状态
      optionsworkStatus: [],
      //批量删除 批量审核 批量打印
      batchStatus: true,
      // 总条数
      total: 0,
      // 最大高度
      maxHeight: null,
      //单据数据
      tableData: [],
      // 已选单据编码
      codeArr: [],
      //详情抽屉
      drawerTitle: "",
      drawer: false,
      direction: "rtl",
      isDrawer: null,
      drawerData: null,
      drawerTableData: [],
      drawerTableLoading: true,
      drawerTableKey: "",
      drawerTableMaxHeight: null,
      // 明细遮罩层
      detailLoading: true,
      //明细查询参数
      queryDetail: {
        pageNum: 1,
        pageSize: 100,
        omCode: "", //单据编码
        workStaff: "",
        customer: "",
        contractNo: "",
        flag: false,
        pp: "",
        workType: this.$route.query.workType,
      },
      // 小数位数
      decimal: 2,
      // 明细总条数
      detailTotal: 0,
      //明细表格key
      tableKey2: "",
      // 明细最大高度
      detailMaxHeight: null,
      // 明细数据
      detailTableData: [],
    };
  },
  activated() {
    const refresh = this.$store.getters["salesStatus/getRejectRefresh"];
    if (refresh == true && this.detailStatus == true) {
      this.$store.dispatch("salesStatus/setRejectRefresh", false);
      this.getDetailList();
    } else if (refresh == true && this.detailStatus == false) {
      this.$store.dispatch("salesStatus/setRejectRefresh", false);
      this.getBillList();
    }
  },
  created() {
    this.getDetailList();
    this.getParameters();
  },

  methods: {
    // 明细按钮
    detailView() {
      this.detailStatus = true;
      this.handleCheckleDetail();
    },

    // 获取单据
    getBillList() {
      this.loading = true;
      listBill(this.queryParams).then((res) => {
        if (res.code == 200) {
          if (res.rows.length > 0) {
            let list = JSON.parse(JSON.stringify(res.rows));
            let last = list[0].invoiceDate,
              tag = 0;
            list.forEach((item, i) => {
              if (list[i].invoiceDate !== last) {
                if (tag == 1) {
                  tag = 0;
                } else if (tag == 0) {
                  tag = 1;
                }
              }
              list[i].tag = tag;
              last = list[i].invoiceDate;
            });
            this.tableData = list;
          } else {
            this.tableData = [];
          }
          this.total = res.total;
          this.tableKey = Math.random();
          this.maxHeight = `${document.documentElement.clientHeight}` - 270;
          this.loading = false;
        }
      });
    },

    // 获取单据状态
    getStatus() {
      dictMatching("sys_invoice_status")
        .then((res) => {
          if (res.code == 200) {
            this.optionsinvoiceStatus = res.data;
          }
        })
        .catch((err) => {
          this.msgError("获取单据状态失败");
        });
    },
    // 获取业务状态
    getWorkStatus() {
      dictMatching("sys_work_status")
        .then((res) => {
          if (res.code == 200) {
            this.optionsworkStatus = res.data;
          }
        })
        .catch((err) => {
          this.msgError("获取业务状态失败");
        });
    },
    // 改变单据状态进行搜索
    invoiceStatusChange(value) {
      this.searchForm.invoiceStatus = value;
      this.searchList();
    },

    //搜索单据
    searchList(type) {
      // 日期转换
      if (
        this.valueDate !== undefined &&
        this.valueDate !== null &&
        this.valueDate.length > 0
      ) {
        if (this.detailStatus == false) {
          this.queryParams.startDate = this.parseTime(this.valueDate[0]);
          this.queryParams.endDate = this.setTime(this.valueDate[1]);
        } else {
          this.queryDetail.startDate = this.parseTime(this.valueDate[0]);
          this.queryDetail.endDate = this.setTime(this.valueDate[1]);
        }
      } else {
        if (this.detailStatus == false) {
          this.queryParams.startDate = "";
          this.queryParams.endDate = "";
        } else {
          this.queryDetail.startDate = "";
          this.queryDetail.endDate = "";
        }
      }
      if (type == "bill") {
        this.queryParams.omCode = this.searchForm.omCode;
        this.queryParams.customer = this.searchForm.customer;
        this.queryParams.workStaff = this.searchForm.workStaff;
        this.queryParams.workStatus = this.searchForm.workStatus;
        this.queryParams.invoiceStatus = this.searchForm.invoiceStatus;
        this.getBillList();
      } else if (type == "detail") {
        this.queryDetail.omCode = this.searchForm.omCode;
        this.queryDetail.customer = this.searchForm.customer;
        this.queryDetail.workStaff = this.searchForm.workStaff;
        this.queryDetail.saleType = this.searchForm.saleType;
        this.queryDetail.searchValue = this.searchForm.searchValue;
        this.queryDetail.pp = this.searchForm.pp;
        this.getDetailList();
      }
    },

    // 查询所有
    handleCheckleAll() {
      this.checkClearAll().then(() => {
        this.getBillList();
      });
    },

    // 新增
    jumpAdd() {
      this.$router.push({
        path: "/om/sales/rejectadd",
        query: {
          open: "addStatus",
          workType: this.$route.query.workType,
          fmConfig: this.$route.query.fmConfig,
          timeStamp: new Date().getTime()
        },
      });
    },

    // 查看详情
    jumpDetail(code) {
      this.$router.push({
        path: "/om/sales/rejectview",
        query: {
          detailCode: code,
          open: "seeStatus",
          workType: this.$route.query.workType,
          fmConfig: this.$route.query.fmConfig,
          timeStamp: new Date().getTime()
        },
      });
    },

    // 编辑
    jumpUpdate(code) {
      this.$router.push({
        path: "/om/sales/rejectedit",
        query: {
          detailCode: code,
          open: "updateStatus",
          workType: this.$route.query.workType,
          fmConfig: this.$route.query.fmConfig,
          timeStamp: new Date().getTime()
        },
      });
    },

    //批量选择
    handleSelectionChange(row) {
      this.codeArr = [];
      if (row.length > 0) {
        this.batchStatus = false;
        row.forEach((obj) => {
          this.codeArr.push({ omCode: obj.omCode });
        });
      } else {
        this.batchStatus = true;
      }
    },

    // 批量审核
    batchExamine() {
      this.$confirm("确认审核选中退货通知单", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return examineBill(this.codeArr);
        })
        .then((res) => {
          if (res.code == 200) {
            this.msgSuccess("审核成功");
            this.getBillList();
          }
        });
    },

    // 批量反审核
    batchDeExamine() {
      this.$confirm("确认撤销审核选中退货通知单", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return examineDeBill(this.codeArr);
        })
        .then((res) => {
          if (res.code == 200) {
            this.msgSuccess("撤销成功");
            this.getBillList();
          }
        });
    },

    //批量删除
    batchDelete() {
      this.$confirm("确认删除选中退货通知单", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return deleteBill(this.codeArr);
        })
        .then((res) => {
          if (res.code == 200) {
            this.msgSuccess("删除成功");
            this.getBillList();
          }
        });
    },

    // 删除
    handleDelete(row) {
      let arr = [];
      arr.push({ omCode: row.omCode });
      this.$confirm("确认删除", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return deleteBill(arr);
        })
        .then((res) => {
          if (res.code == 200) {
            this.msgSuccess("删除成功");
            this.getBillList();
          }
        });
    },

    // 单据按钮
    billView() {
      this.detailStatus = false;
      this.handleCheckleAll();
    },

    //查询所有明细
    handleCheckleDetail() {
      this.checkClearAll().then(() => {
        this.getDetailList().then(() => {
          this.$refs.tableDetailHeight.clearFilter();
        });
      });
    },
    // 获取明细
    getDetailList() {
      return new Promise((resolve, reject) => {
        this.detailLoading = true;
        listRejectDetail(this.queryDetail).then((res) => {
          if (res.code == 200) {
            if (res.rows.length > 0) {
              let list = JSON.parse(JSON.stringify(res.rows));
              let last = list[0].om_code,
                tag = 0;
              list.forEach((item, i) => {
                if (list[i].om_code !== last) {
                  if (tag == 1) {
                    tag = 0;
                  } else if (tag == 0) {
                    tag = 1;
                  }
                }
                list[i].tag = tag;
                last = list[i].om_code;
              });
              this.detailTableData = list;
              this.getDecimal();
            } else {
              this.detailTableData = [];
            }
            this.detailTotal = res.total;
            this.tableKey2 = Math.random();
            this.detailMaxHeight =
              `${document.documentElement.clientHeight}` - 270;
            this.detailLoading = false;
            resolve();
          }
        });
      });
    },
    //导出
    handleExport() {
      const queryParams = this.queryDetail;
      this.$confirm("是否确认导出当前退货单明细?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportDetail(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.tag == 1) {
        return "warning-row";
      }
    },
    // 小数位数
    getDecimal() {
      if (this.detailTableData.length > 0) {
        this.detailTableData.forEach((item) => {
          if (item.price !== null && item.price !== undefined) {
            item.price = parseFloat(item.price).toFixed(
              this.parametersSetting.decimalPrice
            );
          }
          if (item.quantity !== null && item.quantity !== undefined) {
            item.quantity = parseFloat(item.quantity).toFixed(
              this.parametersSetting.decimalQuantity
            );
          }
          if (item.amount !== null && item.amount !== undefined) {
            item.amount = parseFloat(item.amount).toFixed(2);
          }
          if (item.wi_quantity !== null && item.wi_quantity !== undefined) {
            item.wi_quantity = parseFloat(item.wi_quantity).toFixed(
              this.parametersSetting.decimalQuantity
            );
          }
        });
      }
    },

    //获取单据参数
    getParameters() {
      return new Promise((resolve, reject) => {
        billParameters({
          formPath: this.$route.query.fmConfig,
        }).then((res) => {
          if (res.code == 200) {
            if (this.parametersSetting.decimalQuantity !== "null") {
              this.parametersSetting.decimalQuantity =
                res.data["precision.quantity"];
            }
            if (this.parametersSetting.decimalPrice !== "null") {
              this.parametersSetting.decimalPrice = res.data["precision.price"];
            }
            this.parametersSetting.invFeature = res.data["inv.feature"];
            this.$refs.tableDetailHeight.doLayout();
            resolve();
          }
        });
      });
    },

    filterTag(value, row) {
      return row.sale_type === value;
    },

    // 清空单据/明细搜索条件
    checkClearAll() {
      return new Promise((resolve, reject) => {
        this.queryParams = {
          pageNum: 1,
          pageSize: 100,
          omCode: "", //单据编码
          customer: "",
          workStaff: "",
          workStatus: "",
          invoiceStatus: "", //单据状态
          workType: this.$route.query.workType,
        };
        (this.valueDate = []),
          // 搜索表单
          (this.searchForm = {
            omCode: "", //单据编码
            startDate: "",
            endDate: "",
            invoiceStatus: "",
            workStaff: "",
            customer: "",
            contractNo: "",
            searchValue: "", //物料名称
            workStatus: "", //业务状态
            pp: "",
          });
        this.queryDetail = {
          pageNum: 1,
          pageSize: 100,
          omCode: "", //单据编码
          workStaff: "",
          customer: "",
          workStaff: "",
          contractNo: "",
          searchValue: "",
          pp: "",
          flag: false,
          workType: this.$route.query.workType,
        };
        resolve();
      });
    },

    //详情
    handleDawer(row) {
      if (this.drawer == false || this.isDrawer !== row) {
        this.isDrawer = row;
        this.drawer = true;
      } else if (this.drawer == true && this.isDrawer == row) {
        this.drawer = false;
      }
      this.drawerTitle = row.om_code + " " + "-" + " " + row.inv_name;
      this.drawerData = row;
      this.drawerTableLoading = true;
      listLink({
        uniqueId: row.unique_id,
      }).then((res) => {
        if (res.code == 200) {
          this.tableKey2 = Math.random();
          this.drawerTableData = res.rows;
          this.getDecimal();
          this.drawerTableMaxHeight =
            `${document.documentElement.clientHeight}` - 320;
          this.drawerTableLoading = false;
        }
      });
    },
    handleViewBill(row) {
      if (row.invoice == "om_invoice_type" && row.invoice_id == "1") {
        this.$router.push({
          path: "/om/sales/orderview",
          query: {
            detailCode: row.code,
            open: "seeStatus",
            workType: "",
            fmConfig: row.form_config,
            timeStamp: new Date().getTime()
          },
        });
      } else if (row.invoice == "om_invoice_type" && row.invoice_id == "2") {
        this.$router.push({
          path: "/om/sales/deliverview",
          query: {
            detailCode: row.code,
            open: "seeStatus",
            workType: "",
            fmConfig: row.form_config,
            timeStamp: new Date().getTime()
          },
        });
      } else if (row.invoice == "om_invoice_type" && row.invoice_id == "3") {
        this.$router.push({
          path: "/om/sales/rejectview",
          query: {
            detailCode: row.code,
            open: "seeStatus",
            workType: "",
            fmConfig: row.form_config,
            timeStamp: new Date().getTime()
          },
        });
      }
    },
    handleClose() {
      this.drawer = false;
    },

    //时间+23时59分59秒
    setTime(date) {
      date.setHours(date.getHours() + 23);
      date.setMinutes(date.getMinutes() + 59);
      date.setSeconds(date.getSeconds() + 59);
      let time = new Date(date);
      return (
        time.getFullYear() +
        "-" +
        (time.getMonth() + 1) +
        "-" +
        time.getDate() +
        " " +
        time.getHours() +
        ":" +
        time.getMinutes() +
        ":" +
        time.getSeconds()
      );
    },

    //打印数据
    getPrint(data) {
      this.listenPrint = data;
      setTimeout(() => {
        this.printData = JSON.parse(JSON.stringify(this.listenPrint));
        this.printData.forEach((obj) => {
          obj.invoiceDate = new Date(obj.invoiceDate);
        });
        this.printData.sort((a, b) => {
          //打印数排序
          return a.invoiceDate - b.invoiceDate;
        });
        this.printData.reverse();
        setTimeout(() => {
          this.printKey = Math.random();
          this.printStatus = true;
          this.open = false;
        }, 200);
      }, 500);
    },
  },

  filters: {
    //时间格式化
    inMaterTime(date) {
      let time = new Date(date);
      return (
        time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate()
      );
    },
  },
};
</script>
<style lang="scss">
.om-reject-box {
  .el-tabs__item {
    font-weight: 700 !important;
  }
  .el-range-editor--medium.el-input__inner {
    height: 32px;
  }
  .el-range-editor--medium .el-range__icon,
  .el-range-editor--medium .el-range__close-icon,
  .el-range-editor--medium .el-range__icon,
  .el-range-editor--medium .el-range__close-icon,
  .el-range-editor--medium .el-range-separator {
    line-height: 24px;
  }
  .order-tab {
    .el-tabs__header {
      margin-bottom: 10px;
    }

    .el-textarea__inner {
      min-height: 115px;
      height: 115px;
      padding: 10px;
    }

    .is-disabled .el-textarea__inner {
      background: #fff;
      color: #333;
    }
  }

  .tab-text {
    font-size: 14px;
    margin-left: 10px;
  }

  .layout-box1 {
    .el-link.is-underline:hover:after {
      border: none;
    }

    .con-top {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .ware-sel {
      width: 150px;

      .el-input__inner {
        height: 28px;
        line-height: 28px;
      }

      .el-input--medium .el-input__icon {
        line-height: 28px;
      }
    }

    .el-input--medium .el-input__icon {
      line-height: 34px;
    }

    .el-table__header-wrapper th,
    .el-table .el-table__fixed-header-wrapper th {
      height: 35px;
    }

    .el-table .warning-row {
      background-color: #f5f7fa;
    }

    .el-table .yellow-row {
      .red-scarlet {
        color: #e6a23c;
      }
    }

    .has-gutter {
      .el-checkbox__inner {
        margin-right: 4px;
      }
    }

    .search-box {
      display: flex;
      margin-bottom: 20px;

      .picker-data {
        min-width: 150px !important;
        width: 150px;

        .el-input__inner {
          width: 150px;
        }
      }

      .search-input {
        display: flex;
        margin-right: 15px;

        .input-data {
          min-width: 200px !important;
          width: 200px;
        }

        .el-input {
          margin-right: 15px;
        }
      }
    }

    .el-table th {
      height: 35px;
    }

    .el-table--medium th,
    .el-table--medium td {
      padding: 4px 0;
      padding-bottom: 3px;
    }

    .el-link--inner {
      margin-left: 3px;
      margin-right: 3px;
      font-size: 12px;
    }
  }

  .el-tag--success {
    background-color: #f0f9eb;
    border-color: #e1f3d8;
    color: #67c23a;
  }

  .el-tag.el-tag--warning {
    background-color: #fdf6ec;
    border-color: #faecd8;
    color: #e6a23c;
  }

  .tip-box1 {
    text-align: center;
    width: 100%;

    span {
      color: #515a6e;
      font-size: 14px;
    }
  }

  .el-drawer__wrapper {
    width: 958px;
    left: inherit;
  }

  .drawer-detail {
    .el-drawer.rtl {
      height: calc(100vh - 85px);
      top: auto;
    }

    .el-drawer__header {
      span {
        color: #333;
        font-size: 16px;
      }

      // text-align: center;
      margin-bottom: 12px;
    }

    .drawer-detail-table {
      padding: 0 15px;
    }

    .drawer-list-box {
      padding: 0 15px 0 0px;
      width: 100%;
      display: flex;
      justify-content: space-between;
      margin-bottom: 20px;

      .drawer-content {
        p {
          margin: 5px 0px 0px 0;
          label {
            font-size: 14px;
            color: #999;
            width: 70px;
            display: inline-block;
            font-weight: normal;
          }

          .la-width {
            width: 43px !important;
          }

          span {
            font-size: 14px;
            flex: 1;
          }
        }
        .drawer-box {
          .awer-l {
            float: left;
            width: 50%;
          }
          .content-t {
            display: flex;
          }
          .awer-r {
            float: left;
            width: 49%;
            margin-left: 1%;
            .con-price {
              p {
                display: flex;
                align-items: center;
                margin-right: 20px;
              }
            }

            .con-height {
              p {
                display: flex;
                height: 36px;
                span {
                  // height: 40px;
                  text-overflow: -o-ellipsis-lastline;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  display: -webkit-box;
                  -webkit-line-clamp: 2;
                  line-clamp: 2;
                  -webkit-box-orient: vertical;
                }
              }
            }
          }
        }
      }

      .drawer-number {
        flex: 0 1 20% !important;

        tr td:nth-of-type(1) {
          width: 50% !important;
        }
      }

      .drawer-table {
        flex: 1;
        margin-left: 15px;
      }

      .inv-table {
        flex: 0 1 58%;
      }

      h2 {
        font-size: 14px;
        margin-top: 10px;
        margin-bottom: 5px;
        margin-left: 10px;
      }

      .box-bottom {
        margin-bottom: 15px;
      }

      p {
        margin: 8px 0;
        font-size: 15px;
      }

      .table-border {
        background-color: #f7f7f8;
        border-radius: 5px;
        padding: 8px 0;
        min-height: 127px;
      }

      table {
        width: 100%;

        td {
          text-align: left;
          padding: 2px 10px;
          font-size: 14px;
          // width: 50%;
        }

        tr td:nth-of-type(1) {
          color: #999;
        }
      }

      .table-left {
        tr td:nth-of-type(1) {
          width: 24%;
        }
      }

      .table-right {
        tr td:nth-of-type(1) {
          width: 20%;
        }
      }
    }
  }
}

.v-modal {
  display: none;
}

:focus {
  outline: 0;
}
</style>
